/**  
* @Title: MtonsResolver.java
* @Package cn.net.mtons.core
* @Description: TODO
* @author ma jinjian  
* @date 2016年1月23日 下午11:45:25
* @version V1.0  
*/ 
package cn.net.mtons.core;

import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import cn.net.mtons.model.entity.form.MtonsForm;

/**
 * @ClassName: MtonsResolver
 * @Description: TODO
 * @author ma jinjian
 * @date 2016年1月23日 下午11:45:25
 *
 */
public class MtonsResolver implements HandlerMethodArgumentResolver {
	
	/* (non-Javadoc)
	 * @see org.springframework.web.method.support.HandlerMethodArgumentResolver#resolveArgument(org.springframework.core.MethodParameter, org.springframework.web.method.support.ModelAndViewContainer, org.springframework.web.context.request.NativeWebRequest, org.springframework.web.bind.support.WebDataBinderFactory)
	 */
	@Override
	public Object resolveArgument(MethodParameter parameter,
			ModelAndViewContainer model, 
			NativeWebRequest request,
			WebDataBinderFactory binder) throws Exception {
		return request.getAttribute( "form", NativeWebRequest.SCOPE_REQUEST );	
	}

	/* (non-Javadoc)
	 * @see org.springframework.web.method.support.HandlerMethodArgumentResolver#supportsParameter(org.springframework.core.MethodParameter)
	 */
	@Override
	public boolean supportsParameter(MethodParameter parameter) {
		return MtonsForm.class.isAssignableFrom( parameter.getParameterType() );
	}

}
